/**
 * chenuu.com
 * 
 * @author  zhaoxu.com@gmail.com
 * @created 2012-11-9
 */
package com.chenuu.integration.dropbox.model;

import java.util.Map;

import com.chenuu.common.utils.MapUtil;

/**
 *
 */
public class DropboxAccount {
	
	/** The user's ISO country code. */
	public final String country;

	/** The user's "real" name. */
	public final String displayName;

	/** The user's quota, in bytes. */
	public final long quota;

	/** The user's quota excluding shared files. */
	public final long quotaNormal;

	/** The user's quota of shared files. */
	public final long quotaShared;

	/** The user's account ID. */
	public final long uid;

	/** The url the user can give to get referral credit. */
	public final String referralLink;

	/**
	 * Creates an account from a Map.
	 * 
	 * @param map
	 *            a Map that looks like:
	 * 
	 *            <pre>
	 * {"country": "",
	 *  "display_name": "John Q. User",
	 *  "quota_info": {
	 *    "shared": 37378890,
	 *    "quota": 62277025792,
	 *    "normal": 263758550
	 *   },
	 *  "uid": "174"}
	 * </pre>
	 */
	public DropboxAccount(Map<String, Object> map) {
		country = (String) map.get("country");
		displayName = (String) map.get("display_name");
		uid = MapUtil.getLong(map, "uid");
		referralLink = (String) map.get("referral_link");

		Object quotaInfo = map.get("quota_info");
		@SuppressWarnings("unchecked")
		Map<String, Object> quotamap = (Map<String, Object>) quotaInfo;
		quota = MapUtil.getLong(quotamap, "quota");
		quotaNormal = MapUtil.getLong(quotamap, "normal");
		quotaShared = MapUtil.getLong(quotamap, "shared");
	}

	/**
	 * Creates an account object from an initial set of values.
	 */
	protected DropboxAccount(String country, String displayName, long uid, String referralLink,
			long quota, long quotaNormal, long quotaShared) {
		this.country = country;
		this.displayName = displayName;
		this.uid = uid;
		this.referralLink = referralLink;
		this.quota = quota;
		this.quotaNormal = quotaNormal;
		this.quotaShared = quotaShared;
	}
}
